Linux Journal October 2011 by Linux Journal
Author:Linux Journal
Language: eng
Format: mobi, epub
Tags: ENet, ipset, Lustre, Mustache.js, Linux, SSDs, tcpdump
Publisher: Belltown Media
Published: 2011-09-30T07:00:00+00:00
* * *
FEATURES
Network Programming with ENet
Cross-platform network prograMming made easy.
MIKE DIEHL
Creating a multiplayer game can be a lot of fun, but navigating the complexities of IP network programming can be a headache. That’s kind of a strange statement, but the two go hand in hand. You can’t write a multiplayer game without some sort of network-based communications, and game-related network programming introduces difficulties not often found with more simple applications. For example, most game developers are concerned with bandwidth utilization and throttling. There’s also player session management to contend with. Then, there’s the problem of message fragmentation, acknowledgement and sequencing. Oh, and you’d really like to be able to make your game run on both Linux and Windows. That’s a tall order for developers who probably are more concerned with writing their games than they are in becoming experts in cross-platform network programming. Fortunately, the ENet library (enet.bespin.org) takes care of these details and presents developers with a simple, flexible and consistent API.
ENet’s event-driven programming model makes client session management very simple. The library dispatches an event when a peer connects or disconnects, and when a message is received from a peer. The developer simply writes event handlers that take care of initializing and deallocating resources, and acting upon incoming messages. This means you don’t have to worry about the complexities of forking, preforking, threading or nonblocking calls to connect() and accept() in order to handle multiple connections. With ENet, all you do is make periodic calls to its event dispatcher and handle the events as they come in.
ENet provides for both reliable and unreliable transmission. The networking industry really needs to find a better term than “unreliable”, however. Unreliable means that a packet will be sent out, but the receiving end won’t be expected to acknowledge receiving the packet. In a “reliable” protocol, every packet must be acknowledged upon receipt. If a peer sends out a packet and requests acknowledgement and doesn’t receive it in a timely fashion, the packet will be resent automatically until it is acknowledged, or the peer is deemed to be unreachable. The nice thing about ENet is that the same API provides both reliable and unreliable semantics.
ENet also makes it easy to write real-time client-server applications by taking care of packet fragmentation and sequencing chores for you. Put simply, fragmentation and reassembly is done automatically and is transparent to the developer. Sequencing also is handled transparently and can be turned on and off at will. ENet’s concept of a communications channel is related to sequencing. ENet buffers each channel separately and empties each buffer in numerical sequence. The end result is that you can transmit multiple data streams and that lower-numbered channels have higher priority. For example, you could put all real-time game update packets into channel 1, while system status packets could be in a lower-priority channel.
For the sake of demonstration, I discuss both the client and server for a simple chat program. The code I’m using is based on a 3-D video game I’m writing in my limited free time.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25286)
Hello! Python by Anthony Briggs(24338)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23432)
Kotlin in Action by Dmitry Jemerov(22511)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21974)
Dependency Injection in .NET by Mark Seemann(21845)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20710)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19523)
Grails in Action by Glen Smith Peter Ledbrook(18605)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17033)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15843)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13690)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11853)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11151)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10621)
Hit Refresh by Satya Nadella(9199)
The Kubernetes Operator Framework Book by Michael Dame(8570)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8400)
Robo-Advisor with Python by Aki Ranin(8360)